package leetcode100;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class lc010 {
    public static void main(String[] args) {
        Tree tree = new Tree();
        TreeNode root = tree.root;
        tree.visit();
        List<Integer> list = inorderTraversal(root);
        System.out.println(list);

    }

    public static List<Integer> inorderTraversal(TreeNode root) {
        ArrayList<Integer> list = new ArrayList<>();
        LinkedList<TreeNode> stack = new LinkedList<>();
        TreeNode cur = null;
        boolean leftFlag = false;
        if (root == null) return list;
        cur = root;
        while (cur != null || !stack.isEmpty()) {
            /*左*/
            while(cur!=null) {
                stack.push(cur);
                cur = cur.left;
            }
            /*根*/
            cur = stack.pop();
            list.add(cur.val);
            /*右*/
            cur = cur.right;

        }
        return list;
    }


}
